package Calculation;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-10-07
 * Time: 10:58
 */
/*LCR 179. 查找总价格为目标值的两个商品*/
class Solution6 {
    public int[] twoSum(int[] price, int target) {
        int n = price.length;
        int left = 0 , right = n-1;
        int[] car = {-1,-1};
        while(left < right){
            int result = sum(price[left],price[right]);
            if(result < target){
                left++;
            }else if(result > target){
                right--;
            }else{
                car[0] = price[left];
                car[1] = price[right];
                return car;
            }
        }
        return car;

    }
    public int sum(int a , int b){
        int sum = a + b;
        return sum;
    }
}
public class Test6 {

}
